<?php
include("check.php");
include("check2.php");
include_once("../function.php");

header("Content-Type: text/html;charset=utf-8");
session_start();

#搜索商品
if ($_POST['Search']){
	$SearchContent=$_POST['SearchContent'];
	$TimeStart=$_POST['TimeStart'];
	$TimeEnd=$_POST['TimeEnd'];
	if ($TimeStart!=NULL){
		if ($TimeEnd==NULL){
			$TimeEnd=now();	
		}
		$_SESSION['SearchTime']="and (cdate>='".$TimeStart."' and cdate<='".$TimeEnd."') or (sdate>='".$TimeStart."' and sdate<='".$TimeEnd."')";	
	}else{
		$_SESSION['SearchTime']=NULL;		
	}
	if ($SearchContent!=NULL){
		$SearchType=$_POST['SearchType'];
		if ($SearchType==1){
			#搜索订单编号
			$_SESSION['Search']="and ordersnumber like '%".$SearchContent."%'";
		}else if($SearchType==2){
			$_SESSION['Search']="and userid like '%".$SearchContent."%'";	
		}else if($SearchType==2){
			$_SESSION['Search']="and username like '%".$SearchContent."%'";
		}
	}else{
		$_SESSION['Search']=NULL;	
	}
}else{
	if ($_GET['page']==NULL){
		$_SESSION['Search']=NULL;	
		$_SESSION['SearchTime']=NULL;
	}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/table.css" rel="stylesheet" type="text/css">
<link href="css/style1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="./awesome/css/font-awesome.min.css"/>
<script src="../js/calendar.js"></script>
    <link href="../layui-master/dist/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../layui-master/dist/layui.js"></script>
    <script src="./js/style.js" type="text/javascript" charset="utf-8"></script>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#TimeStart' //指定元素
            });
            laydate.render({
                elem: '#TimeEnd' //指定元素
            });
        });
    </script>
<title>订单列表</title>
</head>
<body>
<?php
$title="全部订单";
include_once("./public/header_nav.html");
?>
	<form name="form1" method="post" action="?">
    <div style="margin-top: 0.5rem" class="ziti">
    <select style="width: 3rem" name="SearchType" id="SearchType">
            <option value="1">订单编号</option>
      </select>
          <input style="background-color: #f2fbc4;border: 1px solid;border-radius: 5px" type="text" name="SearchContent" id="SearchContent">
          搜索时间范围：
          <input type="text" name="TimeStart" id="TimeStart" style="width:150px;background-color: #f2fbc4;border: 1px solid;border-radius: 5px" ">
          至
          <input type="text" name="TimeEnd" id="TimeEnd" style="width:150px;background-color: #f2fbc4;border: 1px solid;border-radius: 5px" ">
        <p style="text-align: center;margin: 0.3rem auto"><input type="submit" name="Search" id="Search" class="button_green" value="搜  索"></p>
    </div>
<table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class=" table1">

      <?php
	  	$pagesize = 5; //设置每页记录数
	  	$sql = "SELECT * FROM `orders` WHERE 1=1 and uid=".$_SESSION['ID']." ".$_SESSION['Search']." ".$_SESSION['SearchTime']."";
		if($query = mysql_query($sql)){
	  		$sum = mysql_num_rows($query); //计算总记录数 
		}else{
			$sum=0;	
		}
		if($sum % $pagesize == 0) //计算总页数 
			$total = (int)($sum/$pagesize); 
		else 
			$total = (int)($sum/$pagesize) + 1; 
			if (isset($_GET['page'])) //获得页码 
			{ 
				$p = (int)$_GET['page'];
			} 
			else 
			{ 
				$p = 1;
			}
			if ($p>$total){
				$p=$total;	
			}
		$start = $pagesize * ($p - 1); //计算起始记录 
      	$sql = "SELECT * FROM `orders` WHERE 1=1 and uid=".$_SESSION['ID']." ".$_SESSION['Search']." ".$_SESSION['SearchTime']." order by id desc limit ".$start.",".$pagesize;
		if($query = mysql_query($sql)){
		while ($row=mysql_fetch_array($query)){
	  ?>
        <tr>
            <td style="color: #fff;background-color: #ec9a96" height="10" colspan="11" align="center">我的订单</td>
        </tr>
      <tr>
        <td align="center">订单号：<?=$row['ordersnumber']?></td>
        <td align="center">状态：<?php if($row['issend']==0){?>未发货<?php }else if($row['issend']==1){ ?>已发货<?php }else if($row['issend']==2){?>已退款<?php }?></td>
<!--        <td align="center"><a href="ordercontent.php?oid=--><?//=$row['id']?><!--&page=--><?//=$p?><!--" style="text-decoration:none">查看</a></td>-->
      </tr>
      <tr>
          <td>商品名称：<?php
                   foreach (unserialize($row['goods']) as $value)
                   {
                       ?>
                       <p style="color: red"><?=$value['goodsname']?></p>
                       <?php
                   }
              ?>
          </td>
          <td>商品价格：<?php
              foreach (unserialize($row['goods']) as $value)
              {
                  ?>
                  <p style="color: red"><?=$value['price']?> 元</p>
                  <?php
              }
              ?>
          </td>
      </tr>
            <tr>
                <td>商品数量：<?php
                    echo count(unserialize($row['goods']));
                    ?>
                </td>
                <td>订单总价：<?php
                    echo $row['dpid']." 元";
                    ?>
                </td>
            </tr>
            <tr>
                <td>会员编号：<?php
                    echo $row['userid'];
                    ?>
                </td>
                <td>会员姓名：<?php
                    echo $row['username'];
                    ?>
                </td>
            </tr>
            <tr>
                <td>联系电话：<?php
                    echo $row['usertel'];
                    ?>
                </td>
                <td>联系地址：<?php
                    echo $row['useraddress'];
                    ?>
                </td>
            </tr>
            <tr>
                <td>物流公司：<?php
                    echo $row['logistics'];
                    ?>
                </td>
                <td>物流编号：<?php
                    echo $row['logisticsno'];
                    ?>
                </td>
            </tr>
      <?php
			}
		}
	  ?>
    </table>
    <table width="100%" border="0" class="ziti">
          <tr>
            <td align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
          </tr>
        </table>
   </form>
<?php include_once ("public/footer_nav.html")?>
</body>
</html>